import { useState } from "react";

// 数据不可修改，只能替换。(所有的数据类型，报错对象)
// count++ 视图不变
// setCount(count + 1); 视图改变

function App() {
  const [count, setCount] = useState(0);
  const [form, setForm] = useState({ name: "z", age: 23 });
  const add = () => {
    setCount(count + 1);
  };

  const changeName = () => {
    setForm({ ...form, name: form.name + "-" });
  };
  return (
    <div className="App">
      <h1>This is useState</h1>
      <div>{count}</div>
      <button onClick={add}>Add</button>
      <div>
        {form.name}-{form.age}
      </div>
      <button onClick={changeName}>changeName</button>
    </div>
  );
}

export default App;
